package com.playball.lottery.frm;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;

import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.GridView;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.playball.lottery.R;
import com.playball.lottery.ApplicationData;
import com.playball.lottery.base.BaseActivity;
import com.playball.lottery.eventmanger.EventManager;
import com.playball.lottery.eventmanger.EventType;
import com.playball.lottery.frm.score.ScoreFiltergridviewAdapter;
import com.playball.lottery.frm.score.ScoreOnlineListAdapter;
import com.playball.lottery.nt.GetRequestParams;
import com.playball.lottery.util.ConvertJsonToList;
import com.playball.lottery.util.DateUtil;
import com.playball.lottery.util.FrmWorkStatus;
import com.playball.lottery.util.LotConstants;
import com.playball.lottery.util.MyPreference;


/**
 * 比分
 * 
 * @ClassName: ScoreMainActivity
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author vanszhen
 * @date 2014年7月7日 下午2:48:53 frm------------------>act
 */
public class ScoreMainActivity extends BaseActivity implements LotConstants {
	boolean isrun = false;
	private Context context = null;
	private TextView titlename;
	// private TextView tv_lot_play_name;
	// private Button bt_lot_play_se;
	private Button bt_refresh;
	private Button bt_all;
	private Button bt_unopen;
	private Button bt_present;
	private Button bt_done;
	private Button bt_focus;
	private ListView lv_score_list;
	// private View score_lv_loading;
	// private View score_lv_tip;
	/** 当前显示玩法ID 默认足球90,全部0 */
	private int lotID = 90;// 正式改为90,0做测试用
	/** 当前显示玩法ID 默认足球90,全部0 */
	private String strLot = "竞彩足球";
	// private int lianSaiType = 0;
	/**
	 * 0：全部 1：未开赛 2：进行中 3：已完场 4：我的关注
	 */
	private int matchState = 0;
	/** 最开始的获取的全部数据,之后随着数据刷新不断更新 */
	private List<Map<String, Object>> AllDataList;
	/** 填充到listview的本地数据(除我的关注) */
	private List<Map<String, Object>> mDataList;
	/** 填充到listview我的关注的本地数据 */
	private List<Map<String, Object>> fDataList;
	/** 刷新获取的数据 */
	private List<Map<String, Object>> refreshList;
	/** 我的关注存储的的数据 */
	private List<Map<String, Object>> FaviList;
	/** 比分适配器 */
	private ScoreOnlineListAdapter scoreAdapter;
	/** 彩种ID */
	private String strLotId = "0";
	/** 筛选按钮点击后对话框中赛事简称的个数 */
	private int intselect;
	/** 最后刷新时间，用于保存服务器返回时间 */
	private String LastTime = "0";
	// /** 是否高亮 */
	// boolean isGaoLiang = false;
	/** 声音 */
	private SoundPool sp;
	private HashMap<Integer, Integer> spMap;
	/** 我的关注数量 */
	private static TextView score_tv_focusNum;
	// 高亮回复正常
	private final int UPDATE_TEXT = 1;
	private Timer mTimer;
	private TimerTask mTimerTask;
	private Handler mHandler;
	boolean isFirst = true;
	boolean isFirst2 = true;
	/** 我的关注数量 */
	int focus;
	boolean isFirst4 = true;
	boolean isRequest = false;
	// ShowTipDialog showdialog = new ShowTipDialog();
	/** 竞彩足球我的关注存储类sharedpreferences XML名字 */
	private String jczqfav = "jczqfav";
	/** 北单我的关注存储类sharedpreferences XML名字 */
	private String bdfav = "bdfav";
	/** 菜单弹出框 */
	private PopupWindow menu_popupWindow;
	/** 菜单弹出框 */
	private View menutypeview;
	boolean isFirstShowTip = false;

	/** 筛选按钮中gridview 数据适配器 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.score_online);
		context = ScoreMainActivity.this;
		seltitleslist = new ArrayList<String>();
		titleBar();
		initView();
		initListener();

		// 初始化声音
		sp = new SoundPool(2, AudioManager.STREAM_MUSIC, 0);
		spMap = new HashMap<Integer, Integer>();
		spMap.put(1, sp.load(context, R.raw.dingdong, 1));
		spMap.put(2, sp.load(context, R.raw.shaozi, 1));

		mHandler = new Handler() {
			public void handleMessage(Message msg) {
				super.handleMessage(msg);
				switch (msg.what) {
				case UPDATE_TEXT:
					// 2s后还原低亮
					if (scoreAdapter != null) {
						if (matchState != 4) {
							scoreAdapter.setLightOffData(mDataList);
						} else {
							scoreAdapter.setLightOffData(fDataList);
						}
						scoreAdapter.notifyDataSetChanged();
					}
					break;
				default:
					break;
				}
			}
		};
	}

	public void onPause() {
		super.onPause();
		
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		// TODO Auto-generated method stub
		isFirst = true;// test
		isFirst2 = true;
		isFirst4 = true;
		isPause = false;
		// 开启计时器刷新数据
		if (handler == null) {
			setupData();
			handler = new Handler();
			handler.postDelayed(runnable, 5000);
		}

		if (!isrun) {
			// 只有高亮状态才开启定时器
			mTimer = new Timer();
			mTimerTask = new TimerTask() {
				public void run() {
					// Log.i("mTimerTask", "mTimerTask");
					mHandler.sendEmptyMessage(UPDATE_TEXT);
					isrun = true;
				}
			};
			mTimer.schedule(mTimerTask, 0, 2000);
		}
		
	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		if (menu_popupWindow != null) {
			menu_popupWindow.dismiss();
		}
		// 关闭定时器
		if (mTimerTask != null) {
			mTimerTask.cancel(); // 将原任务从队列中移除
		}
	}

	/**
	 * 初始化视图
	 */
	public void initView() {
		// tv_lot_play_name = (TextView) findViewById(R.id.score_lot_play_name);
		// bt_lot_play_se = (Button) findViewById(R.id.score_bt_se_lot);
		bt_refresh = (Button) findViewById(R.id.score_refresh);
		bt_all = (Button) findViewById(R.id.score_bt_all);
		bt_unopen = (Button) findViewById(R.id.score_bt_unopen);
		bt_present = (Button) findViewById(R.id.score_present);
		bt_done = (Button) findViewById(R.id.score_bt_done);
		bt_focus = (Button) findViewById(R.id.score_bt_focus);
		score_tv_focusNum = (TextView) findViewById(R.id.score_tv_focusNum);
		bt_all.setEnabled(false);
		lv_score_list = (ListView) findViewById(R.id.score_list);
		lv_score_list.setDividerHeight(0);

		// score_lv_loading = findViewById(R.id.score_lv_loading);
		// score_lv_tip = findViewById(R.id.score_lv_tip);
	}

	/**
	 * 初始化监听器
	 */
	public void initListener() {
		// 全部 未开赛 进行中 已完场 我的关注按钮事件
		setBtnOnClick(R.id.score_bt_all);
		setBtnOnClick(R.id.score_bt_unopen);
		setBtnOnClick(R.id.score_present);
		setBtnOnClick(R.id.score_bt_done);
		setBtnOnClick(R.id.score_bt_focus);
	}

	/**
	 * 请求数据
	 */
	public void setupData() {
		// 控制我的关注保存时间,去掉关注中开赛时间过去48小时的
		FaviList = new ArrayList<Map<String, Object>>();
		if (lotID == LOT_ID_JCZQ) {
			// 从保存的本地文件中读取
			FaviList = MyPreference.getInstance(context).getStringArrayPreflist2(context, jczqfav, "jczqfavoritos");
			if (FaviList != null && (!FaviList.equals("[]"))) {
				// Log.e("setupData0", "Favlist= " + Favlist.toString());
				String currentTime = DateUtil.getFullDateTime();
				for (int j = 0; j < FaviList.size(); j++) {
					// 开赛时间
					String i3Time = String.valueOf(FaviList.get(j).get("i3"));
					String year = DateUtil.getYear();
					String KaisaiTime = year + "-" + i3Time + ":00";
					// 比较当前时间和开赛时间，判断开赛时间是否已经过去48小时
					long hours = DateUtil.getDiffTime2(currentTime, KaisaiTime);
					// 如果超过48小时，自动删除,Preference保存文件
					if (hours >= 48) {
						FaviList.remove(j);
						--j;
					}
				}
				MyPreference.getInstance(context).setStringArrayPreflist2(context, jczqfav, "jczqfavoritos", FaviList);
			}
		} else if (lotID == LOT_ID_BD) {
			// 从保存的本地文件中读取
			FaviList = MyPreference.getInstance(context).getStringArrayPreflist2(context, bdfav, "bdfavoritos");
			if (FaviList != null && (!FaviList.equals("[]"))) {
				String currentTime = DateUtil.getFullDateTime();
				// currentTime.toString());
				for (int j = 0; j < FaviList.size(); j++) {
					String i3Time = String.valueOf(FaviList.get(j).get("i3"));
					String year = DateUtil.getYear();
					String KaisaiTime = year + "-" + i3Time + ":00";
					long hours = DateUtil.getDiffTime2(currentTime, KaisaiTime);
					// 如果超过48小时，自动删除,Preference保存文件
					if (hours >= 48) {
						FaviList.remove(j);
						--j;
					}
				}
				MyPreference.getInstance(context).setStringArrayPreflist2(context, bdfav, "bdfavoritos", FaviList);
			}
		}

		// 首次请求数据 //90 非0，0做测试用
		startScoreThread(lotID);
	}

	/**
	 * 发送请求网络数据；；首次全部对阵 数据，加请求对话框
	 */
	private void startScoreThread(int lotId) {
		AsyncLoader task = new AsyncLoader();
		String[] dyn = new String[2];
		JSONObject params = new JSONObject();
		try {
			// 设置请求所需参数
			params.put("LotteryId", lotId);
		} catch (JSONException ex) {
			Log.e("error", ex.toString());
		}
		dyn[0] = params.toString();
		dyn[1] = "mobilallmatchs";// 全部
		task.execute(dyn);
	}

	// 每隔5秒自动刷新数据
	private Handler handler = null;
	protected boolean isPause = false;
	private Runnable runnable = new Runnable() {
		public void run() {
			// 自动刷新
			if (!isPause)
				autoRefreshThread();
			// handler.postDelayed(this, 5000);
			if (isFirst4 && !isRequest) {
				// Log.v("runnable", "isFirst4 0");
				handler.postDelayed(this, 0);
				isRequest = true;
			} else {
				// Log.d("runnable", "5000");
				handler.postDelayed(this, 5000);
			}
		}
	};

	/**
	 * 发送刷新请求网络数据；自动刷新,需时间戳,无需对话框，5s刷新一次
	 */
	private void autoRefreshThread() {
		autoRefreshTask task = new autoRefreshTask();
		String[] dyn = new String[2];
		JSONObject params = new JSONObject();
		try {
			// 设置请求所需参数
			params.put("LotteryId", lotID);
			params.put("lastTime", LastTime);
		} catch (JSONException ex) {
			Log.e("error", ex.toString());
		}
		dyn[0] = params.toString();
		dyn[1] = "mobilpartmatchs";// 部分刷新
		task.execute(dyn);
	}

	/**
	 * 手动刷新
	 */
	private void shouDongRefreshThread() {
		shouDongRefresh task = new shouDongRefresh();
		String[] dyn = new String[2];
		JSONObject params = new JSONObject();
		try {
			// 设置请求所需参数
			params.put("LotteryId", lotID);
			params.put("lastTime", LastTime);
		} catch (JSONException ex) {
			Log.e("error", ex.toString());
		}
		dyn[0] = params.toString();
		dyn[1] = "mobilpartmatchs";// 部分刷新
		task.execute(dyn);
	}

	private boolean isLoading = false;

	/**
	 * 接受全部数据，首次请求数据用，处理网络数据
	 * 
	 * @author Administrator
	 * 
	 */
	class AsyncLoader extends AsyncTask<String, Integer, String> {// 继承AsyncTask
		String action;

		// ShowTipDialog showdialog = new ShowTipDialog();

		// 1.准备运行
		protected void onPreExecute() {
			// showdialog.showDialog(context);
			// score_lv_loading.setVisibility(View.VISIBLE);
			// score_lv_tip.setVisibility(View.GONE);
			isLoading = true;
		}

		// 2.正在后台运行
		protected String doInBackground(String... paramsArr) {
			// 处理后台执行的任务，在后台线程执行
			String strResult = null;
			action = paramsArr[1];
			// 获取请求返回值
			// strResult = GetRequestParams.getScoreRequestResult(paramsArr[0],
			// action, getApplicationContext());
			strResult = GetRequestParams.getScoreRequestResult(paramsArr[0], action, context);
			// Log.e("doInBackground", "strResult= " + strResult);
			// 获取请求返回值
			return strResult;
		}

		// 3.进度更新
		protected void onProgressUpdate(Integer... progress) {
		}

		// 4.完成后台任务
		protected void onPostExecute(String result) {
			// Log.e("onPostExecute", "result= " + result);

			if (result != null) {
				// 服务器不同格式判断
				if (result.contains("Code")) {
					// score_lv_tip.setVisibility(View.VISIBLE);
					AllDataList.clear();
					mDataList.clear();
					scoreAdapter = new ScoreOnlineListAdapter(context, mDataList, matchState, lotID);
					lv_score_list.setAdapter(scoreAdapter);
				} else {
					// 获取全部数据
					if (action.equals("mobilallmatchs")) {
						// 获取全部网络数据
						AllDataList = ConvertJsonToList.getList(result);
						if (AllDataList != null) {
							// 加上参数isCheck isLight
							for (int i = 0; i < AllDataList.size(); i++) {
								AllDataList.get(i).put("isCheck", 0);
								AllDataList.get(i).put("isLight", 0);
							}
						}
					}
				}
				// showSList(matchState);
				if (seltitleslist.size() == 0) {
					showSList(matchState);
				} else {
					if (matchState != 4) {
						handleDataByShort(matchState, seltitleslist);
					}
				}
			} else {
				if (!isFirstShowTip) {
					isFirstShowTip = true;
					Toast.makeText(context, context.getString(R.string.problem_01), Toast.LENGTH_LONG).show();
				}
				// 首次请求数据 //90 非0，0做测试用
				startScoreThread(lotID);
			}
			if (!isFirst4) {
				// showdialog.closeDialog();
				// score_lv_loading.setVisibility(View.GONE);
			}

			isLoading = false;
		}

		// 5.完成后操作
		protected void onCancelled() {
		}
	}

	/**
	 * 刷新最新的数据集合
	 */
	private void refNewestDataList(List<Map<String, Object>> tempList) {
		// /根据是否有最新刷新数据来判断全部list数据是否需要更新,refreshList为空时不用更新AllDataList
		if (refreshList != null && tempList != null) {
			if (refreshList.size() != 0 && tempList.size() != 0) {
				// Log.v("refNewestAllDataList",
				// "refreshList.get(0).containsKey(j1)= "+refreshList.get(0).containsKey("j1"));
				// 将最新刷新的数据更新到全部list数据集合中,以备筛选
				// 从ListView的数据集合中找到要修改的那条数据，修改它，然后用adapter.notifyDataSetChanged();
				if (refreshList.get(0).containsKey("j1")) {// 正常格式
					for (int i = 0; i < tempList.size(); i++) {
						Map<String, Object> OldMap = tempList.get(i);
						String oldmatchID = String.valueOf(OldMap.get("i1"));
						for (int j = 0; j < refreshList.size(); j++) {
							Map<String, Object> newMap = refreshList.get(j);
							// 赛事ID
							String newmatchID = String.valueOf(newMap.get("j1"));
							if (oldmatchID.contains(newmatchID)) {
								// 移除旧的
								tempList.remove(i);
								Map<String, Object> NewMap = new HashMap<String, Object>();
								// 筛选数据
								NewMap.put("i1", String.valueOf(OldMap.get("i1")));// 赛事ID
								NewMap.put("i2", String.valueOf(OldMap.get("i2")));// 赛事简称
								NewMap.put("i3", String.valueOf(OldMap.get("i3")));// 开赛时间
								NewMap.put("i4", String.valueOf(newMap.get("j2")));// 状态
								NewMap.put("i5", String.valueOf(OldMap.get("i5")));// 主队
								NewMap.put("i6", String.valueOf(newMap.get("j6")));// 主队红牌数
								NewMap.put("i7", String.valueOf(newMap.get("j7")));// 主队黄牌数
								NewMap.put("i8", String.valueOf(newMap.get("j3")));// 主队分数
								NewMap.put("i9", String.valueOf(OldMap.get("i9")));// 客队
								NewMap.put("i10", String.valueOf(newMap.get("j9")));// 客队红牌数
								NewMap.put("i11", String.valueOf(newMap.get("j10")));// 客队黄牌数
								NewMap.put("i12", String.valueOf(newMap.get("j4")));// 客队分数
								NewMap.put("i13", String.valueOf(newMap.get("j5")));// 半场比分
								NewMap.put("isCheck", Integer.parseInt(String.valueOf(OldMap.get("isCheck"))));
								NewMap.put("isLight", 0);
								// 加上新的
								tempList.add(i, NewMap);
							}
						}
					}
				} else {// 非正常格式
					for (int i = 0; i < tempList.size(); i++) {
						Map<String, Object> OldMap = tempList.get(i);
						String oldmatchID = String.valueOf(OldMap.get("i1"));
						for (int j = 0; j < refreshList.size(); j++) {
							Map<String, Object> newMap = refreshList.get(j);
							// 赛事ID
							String newmatchID = String.valueOf(newMap.get("mid"));
							if (oldmatchID.contains(newmatchID)) {
								// 移除旧的
								tempList.remove(i);
								Map<String, Object> NewMap = new HashMap<String, Object>();
								// 筛选数据
								NewMap.put("i1", String.valueOf(OldMap.get("i1")));// 赛事ID
								NewMap.put("i2", String.valueOf(OldMap.get("i2")));// 赛事简称
								NewMap.put("i3", String.valueOf(OldMap.get("i3")));// 开赛时间
								NewMap.put("i4", String.valueOf(newMap.get("s")));// 状态
								NewMap.put("i5", String.valueOf(OldMap.get("i5")));// 主队
								NewMap.put("i6", String.valueOf(OldMap.get("i6")));// 主队红牌数
								NewMap.put("i7", String.valueOf(OldMap.get("i7")));// 主队黄牌数
								NewMap.put("i8", String.valueOf(OldMap.get("i8")));// 主队分数
								NewMap.put("i9", String.valueOf(OldMap.get("i9")));// 客队
								NewMap.put("i10", String.valueOf(OldMap.get("i10")));// 客队红牌数
								NewMap.put("i11", String.valueOf(OldMap.get("i11")));// 客队黄牌数
								NewMap.put("i12", String.valueOf(OldMap.get("i12")));// 客队分数
								NewMap.put("i13", String.valueOf(OldMap.get("i13")));// 半场比分
								NewMap.put("isCheck", Integer.parseInt(String.valueOf(OldMap.get("isCheck"))));
								NewMap.put("isLight", 0);
								// 加上新的
								tempList.add(i, NewMap);
							}
						}
					}
				}
			}
		}
	}

	/**
	 * 刷新最新的全部按钮下的数据集合,要显示进球提示及声音
	 */
	private void refreshAllBtn(List<Map<String, Object>> tempList) {
		// /根据是否有最新刷新数据来判断全部list数据是否需要更新,refreshList为空时不用更新AllDataList
		if (refreshList != null && tempList != null) {
			// 将最新刷新的数据更新到全部list数据集合中,以备筛选
			// 从ListView的数据集合中找到要修改的那条数据，修改它，然后用adapter.notifyDataSetChanged();
			if (refreshList.get(0).containsKey("j1")) {// 正常格式
				for (int i = 0; i < tempList.size(); i++) {
					Map<String, Object> OldMap = tempList.get(i);
					String oldmatchID = String.valueOf(OldMap.get("i1"));
					for (int j = 0; j < refreshList.size(); j++) {
						Map<String, Object> newMap = refreshList.get(j);
						// 赛事ID
						String newmatchID = String.valueOf(newMap.get("j1"));
						if (oldmatchID.contains(newmatchID)) {
							// 移除旧的
							tempList.remove(i);
							Map<String, Object> NewMap = new HashMap<String, Object>();
							// 筛选数据
							NewMap.put("i1", String.valueOf(OldMap.get("i1")));// 赛事ID
							NewMap.put("i2", String.valueOf(OldMap.get("i2")));// 赛事简称
							NewMap.put("i3", String.valueOf(OldMap.get("i3")));// 开赛时间
							NewMap.put("i4", String.valueOf(newMap.get("j2")));// 状态
							NewMap.put("i5", String.valueOf(OldMap.get("i5")));// 主队
							NewMap.put("i6", String.valueOf(newMap.get("j6")));// 主队红牌数
							NewMap.put("i7", String.valueOf(newMap.get("j7")));// 主队黄牌数
							NewMap.put("i8", String.valueOf(newMap.get("j3")));// 主队分数
							NewMap.put("i9", String.valueOf(OldMap.get("i9")));// 客队
							NewMap.put("i10", String.valueOf(newMap.get("j9")));// 客队红牌数
							NewMap.put("i11", String.valueOf(newMap.get("j10")));// 客队黄牌数
							NewMap.put("i12", String.valueOf(newMap.get("j4")));// 客队分数
							NewMap.put("i13", String.valueOf(newMap.get("j5")));// 半场比分
							NewMap.put("isCheck", Integer.parseInt(String.valueOf(OldMap.get("isCheck"))));
							NewMap.put("isLight", 0);
							// 加上新的
							tempList.add(i, NewMap);
							// 弹出进球对话框和声音提示及红黄牌声音提示
							// 当进球时给出一个进球的弹窗，并且此场比赛的背景给变掉,进球声音的提示,红黄牌变动声音提示
							// showJinQiuTiShi();
							// j3主分 j4客分 旧i8 i12进球有变动时
							if ((!String.valueOf(newMap.get("j3")).equals(String.valueOf(OldMap.get("i8"))))
									|| (!String.valueOf(newMap.get("j4")).equals(String.valueOf(OldMap.get("i12"))))) {
								Log.v("refreshAllBtn", "进球提示");
								// 弹出进球提示框
								LayoutInflater inflater = LayoutInflater.from(context);
								View view0 = inflater.inflate(R.layout.score_toasthint,
										(ViewGroup) findViewById(R.id.toast_layout_root));
								// 设置提示信息
								TextView name = (TextView) view0.findViewById(R.id.score_popuphint_saishiName);
								name.setText(String.valueOf(OldMap.get("i2")));
								TextView time = (TextView) view0.findViewById(R.id.score_popuphint_time);
								time.setText(String.valueOf(newMap.get("j2")));
								TextView hteam = (TextView) view0.findViewById(R.id.score_popuphint_hteam);
								// 名字过长截取9位
								String strhteam = String.valueOf(OldMap.get("i5"));
								String strH;
								if (strhteam.length() < 10) {
									strH = strhteam;
								} else {
									strH = strhteam.substring(0, 9);
								}
								hteam.setText(strH);
								TextView vteam = (TextView) view0.findViewById(R.id.score_popuphint_vteam);
								// 名字过长截取9位
								String strvteam = String.valueOf(OldMap.get("i9"));
								String strV;
								if (strvteam.length() < 10) {
									strV = strvteam;
								} else {
									strV = strvteam.substring(0, 9);
								}
								vteam.setText(strV);
								TextView hscore = (TextView) view0.findViewById(R.id.score_popuphint_hscore);
								hscore.setText(String.valueOf(newMap.get("j3")));
								TextView vscore = (TextView) view0.findViewById(R.id.score_popuphint_vscore);
								vscore.setText(String.valueOf(newMap.get("j4")));
								// 创建提示
								Toast toast = new Toast(context);
								toast.setDuration(Toast.LENGTH_LONG);
								toast.setView(view0);
								// app = (ApplicationBall) getApplication();
								int h = ApplicationData.getInstance().getTabHostHeight();
								Log.i("进球提示all", "h= " + h);
								toast.setGravity(Gravity.CENTER | Gravity.BOTTOM, 0, h);
								toast.show();
								// 此场比赛的背景给变掉
								Log.v("refreshAllBtn", "改变list背景");
								for (int n = 0; n < AllDataList.size(); n++) {
									if (n == i) {
										AllDataList.get(n).put("isLight", 1);
									}
								}
								// Log.i("改变list背景后",
								// "refreshAllBtn mDataList= " +
								// mDataList.toString());
								// Log.e("改变list背景后",
								// "refreshAllBtn AllDataList= " +
								// AllDataList.toString());
								// 声音提示
								if (MyPreference.getInstance(context).getSoundFlgJQ()) {
									playSounds(1, 0);
								}
							}
							// 红黄牌变动声音提示 旧 显示 主队红i6黄i7 客队红i10 黄i11 刷新
							// 主队红j6黄j7 客队红j9 黄j10
							if ((!String.valueOf(newMap.get("j6")).equals(String.valueOf(OldMap.get("i6"))))
									|| (!String.valueOf(newMap.get("j7")).equals(String.valueOf(OldMap.get("i7"))))
									|| (!String.valueOf(newMap.get("j9")).equals(String.valueOf(OldMap.get("i10"))))
									|| (!String.valueOf(newMap.get("j10")).equals(String.valueOf(OldMap.get("i11"))))) {
								Log.v("refreshAllList", "红黄牌变动提示");
								// 播放声音
								if (MyPreference.getInstance(context).getSoundFlgHH()) {
									playSounds(2, 0);
								}
							}
						}
					}
				}
			} else {// 非正常格式
				for (int i = 0; i < tempList.size(); i++) {
					Map<String, Object> OldMap = tempList.get(i);
					String oldmatchID = String.valueOf(OldMap.get("i1"));
					for (int j = 0; j < refreshList.size(); j++) {
						Map<String, Object> newMap = refreshList.get(j);
						// 赛事ID
						String newmatchID = String.valueOf(newMap.get("mid"));
						if (oldmatchID.contains(newmatchID)) {
							// 移除旧的
							tempList.remove(i);
							Map<String, Object> NewMap = new HashMap<String, Object>();
							// 筛选数据
							NewMap.put("i1", String.valueOf(OldMap.get("i1")));// 赛事ID
							NewMap.put("i2", String.valueOf(OldMap.get("i2")));// 赛事简称
							NewMap.put("i3", String.valueOf(OldMap.get("i3")));// 开赛时间
							NewMap.put("i4", String.valueOf(newMap.get("s")));// 状态
							NewMap.put("i5", String.valueOf(OldMap.get("i5")));// 主队
							NewMap.put("i6", String.valueOf(OldMap.get("i6")));// 主队红牌数
							NewMap.put("i7", String.valueOf(OldMap.get("i7")));// 主队黄牌数
							NewMap.put("i8", String.valueOf(OldMap.get("i8")));// 主队分数
							NewMap.put("i9", String.valueOf(OldMap.get("i9")));// 客队
							NewMap.put("i10", String.valueOf(OldMap.get("i10")));// 客队红牌数
							NewMap.put("i11", String.valueOf(OldMap.get("i11")));// 客队黄牌数
							NewMap.put("i12", String.valueOf(OldMap.get("i12")));// 客队分数
							NewMap.put("i13", String.valueOf(OldMap.get("i13")));// 半场比分
							NewMap.put("isCheck", Integer.parseInt(String.valueOf(OldMap.get("isCheck"))));
							NewMap.put("isLight", 0);
							// 加上新的
							tempList.add(i, NewMap);
						}
					}
				}
			}
		}
	}

	/**
	 * 刷新最新的进行中的listview显示数据集合,已经开赛的加入，完场的剔除, // 将最新刷新的数据更新到全部list数据集合中,以备筛选 //
	 * 从ListView的数据集合中找到要修改的那条数据，修改它，然后用adapter.notifyDataSetChanged();
	 */
	private void refreshPresentBtn(String strResult) {
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		list = new ArrayList<Map<String, Object>>(refreshList);
		// 去掉完再比较大小
		if (strResult.contains("完")) {
			if (strResult.contains("j1")) {// 正常格式
				for (int j = 0; j < list.size(); j++) {
					Map<String, Object> newMap = list.get(j);
					if ("完".equals(String.valueOf(newMap.get("j2")))) {
						list.remove(j);
						// --j;
					}
				}
			} else {// 非正常格式
				for (int j = 0; j < list.size(); j++) {
					Map<String, Object> newMap = list.get(j);
					if ("完".contains(String.valueOf(newMap.get("s")))) {
						// 移除旧的
						list.remove(j);
						// --j;
					}
				}
			}
		}

		// /将未开赛转进行中的加入
		if (mDataList.size() < list.size()) {
			Log.i("refreshPresentBtn", "refreshList.size()容量大");
			/** 不含ischeck字段的数据 */
			List<Map<String, Object>> nocheckList = new ArrayList<Map<String, Object>>();
			// 更新最新全部list
			refNewestDataList(AllDataList);
			// 根据状态筛选
			// nocheckList = getDataByState(matchState);
			if (seltitleslist != null && seltitleslist.size() != 0) {
				nocheckList.addAll(getHandleDataByShortList(matchState, seltitleslist));
			} else {
				nocheckList.addAll(getDataByState(matchState));
			}
			// 加上关注状态
			// 待测试
			mDataList.clear();
			mDataList.addAll(AddCheck(nocheckList));
			// Log.v("refreshPresentBtn", "mDataList=" + mDataList.toString());
		} else {
			// 如果有进球等变化需要更新全部list
			if (strResult.contains("j1")) {
				// 更新最新全部list
				refNewestDataList(AllDataList);
			}
			// /b 将进行中的比赛数据刷新；c将进行中转完场的剔除
			modifyINGChange(strResult);
		}
	}

	/**
	 * 刷新最新的我的关注数据集合,比较全部list和收藏list，取出全部list中和收藏list
	 * ID一样的，作为我的关注的数据集合,要显示进球提示及声音
	 */
	private void refreshFocusBtn(List<Map<String, Object>> fList) {
		// /根据是否有最新刷新数据来判断全部list数据是否需要更新,refreshList为空时不用更新AllDataList
		if (refreshList != null && fList != null) {
			// 将最新刷新的数据更新到全部list数据集合中,以备筛选
			// 从ListView的数据集合中找到要修改的那条数据，修改它，然后用adapter.notifyDataSetChanged();
			if (refreshList.get(0).containsKey("j1")) {// 正常格式
				// Log.v("refNewestAllDataList",
				// "refreshList.get(0).containsKey(j1)= "+refreshList.get(0).containsKey("j1"));
				List<Map<String, Object>> newDataList = new ArrayList<Map<String, Object>>();
				for (int i = 0; i < fList.size(); i++) {
					Map<String, Object> OldMap = fList.get(i);
					String oldmatchID = String.valueOf(OldMap.get("i1"));
					for (int j = 0; j < refreshList.size(); j++) {
						Map<String, Object> newMap = refreshList.get(j);
						// 赛事ID
						String newmatchID = String.valueOf(newMap.get("j1"));
						if (oldmatchID.equals(newmatchID)) {
							// 移除旧的
							// fList.remove(i);
							Map<String, Object> NewMap = new HashMap<String, Object>();
							// 筛选数据
							NewMap.put("i1", String.valueOf(OldMap.get("i1")));// 赛事ID
							NewMap.put("i2", String.valueOf(OldMap.get("i2")));// 赛事简称
							NewMap.put("i3", String.valueOf(OldMap.get("i3")));// 开赛时间
							NewMap.put("i4", String.valueOf(newMap.get("j2")));// 状态
							NewMap.put("i5", String.valueOf(OldMap.get("i5")));// 主队
							NewMap.put("i6", String.valueOf(newMap.get("j6")));// 主队红牌数
							NewMap.put("i7", String.valueOf(newMap.get("j7")));// 主队黄牌数
							NewMap.put("i8", String.valueOf(newMap.get("j3")));// 主队分数
							NewMap.put("i9", String.valueOf(OldMap.get("i9")));// 客队
							NewMap.put("i10", String.valueOf(newMap.get("j9")));// 客队红牌数
							NewMap.put("i11", String.valueOf(newMap.get("j10")));// 客队黄牌数
							NewMap.put("i12", String.valueOf(newMap.get("j4")));// 客队分数
							NewMap.put("i13", String.valueOf(newMap.get("j5")));// 半场比分
							NewMap.put("isCheck", Integer.parseInt(String.valueOf(OldMap.get("isCheck"))));
							NewMap.put("isLight", 0);
							// 加上新的
							// fList.add(i, NewMap);
							newDataList.add(NewMap);
							// 弹出进球对话框和声音提示及红黄牌声音提示
							// 当进球时给出一个进球的弹窗，并且此场比赛的背景给变掉,进球声音的提示,红黄牌变动声音提示
							// showJinQiuTiShi();
							// j3主分 j4客分 旧i8 i12进球有变动时
							if ((!String.valueOf(newMap.get("j3")).equals(String.valueOf(OldMap.get("i8"))))
									|| (!String.valueOf(newMap.get("j4")).equals(String.valueOf(OldMap.get("i12"))))) {
								Log.e("refreshFocusList", "进球提示");
								// 弹出进球提示框
								LayoutInflater inflater = LayoutInflater.from(context);
								View view0 = inflater.inflate(R.layout.score_toasthint,
										(ViewGroup) findViewById(R.id.toast_layout_root));
								// 设置提示信息
								TextView name = (TextView) view0.findViewById(R.id.score_popuphint_saishiName);
								name.setText(String.valueOf(OldMap.get("i2")));
								TextView time = (TextView) view0.findViewById(R.id.score_popuphint_time);
								time.setText(String.valueOf(newMap.get("j2")));
								TextView hteam = (TextView) view0.findViewById(R.id.score_popuphint_hteam);
								// 名字过长截取9位
								String strhteam = String.valueOf(OldMap.get("i5"));
								String strH;
								if (strhteam.length() < 10) {
									strH = strhteam;
								} else {
									strH = strhteam.substring(0, 9);
								}
								hteam.setText(strH);
								TextView vteam = (TextView) view0.findViewById(R.id.score_popuphint_vteam);
								// 名字过长截取9位
								String strvteam = String.valueOf(OldMap.get("i9"));
								String strV;
								if (strvteam.length() < 10) {
									strV = strvteam;
								} else {
									strV = strvteam.substring(0, 9);
								}
								vteam.setText(strV);
								TextView hscore = (TextView) view0.findViewById(R.id.score_popuphint_hscore);
								hscore.setText(String.valueOf(newMap.get("j3")));
								TextView vscore = (TextView) view0.findViewById(R.id.score_popuphint_vscore);
								vscore.setText(String.valueOf(newMap.get("j4")));
								// 创建提示
								Toast toast = new Toast(context);
								toast.setDuration(Toast.LENGTH_LONG);
								toast.setView(view0);
								// app = (ApplicationBall) getApplication();
								int h = ApplicationData.getInstance().getTabHostHeight();
								Log.e("进球提示focus", "h= " + h);
								toast.setGravity(Gravity.CENTER | Gravity.BOTTOM, 0, h);
								toast.show();
								// 此场比赛的背景给变掉
								Log.e("refreshFocusList", "改变list背景");
								for (int m = 0; m < fDataList.size(); m++) {
									if (m == i) {
										fDataList.get(m).put("isLight", 1);
									}
								}
								// Log.e("改变list背景",
								// "refreshFocusList fDataList= " +
								// fDataList.toString());
								// Log.v("改变list背景",
								// "refreshFocusList mDataList= " +
								// mDataList.toString());
								// 声音提示
								if (MyPreference.getInstance(context).getSoundFlgJQ()) {
									playSounds(1, 0);
								}
							}
							// 红黄牌变动声音提示 旧 显示 主队红i6黄i7 客队红i10 黄i11 刷新
							// 主队红j6黄j7 客队红j9 黄j10
							if ((!String.valueOf(newMap.get("j6")).equals(String.valueOf(OldMap.get("i6"))))
									|| (!String.valueOf(newMap.get("j7")).equals(String.valueOf(OldMap.get("i7"))))
									|| (!String.valueOf(newMap.get("j9")).equals(String.valueOf(OldMap.get("i10"))))
									|| (!String.valueOf(newMap.get("j10")).equals(String.valueOf(OldMap.get("i11"))))) {
								Log.e("refreshFocusList", "红黄牌变动提示");
								// 播放声音
								if (MyPreference.getInstance(context).getSoundFlgHH()) {
									playSounds(2, 0);
								}
							}
						}
					}
				}
				// 复制newDataList给fDataList
				fDataList = new ArrayList<Map<String, Object>>(newDataList);
				changeFocusNum(fDataList.size());
				if (lotID == LOT_ID_JCZQ) {
					// 存贮
					MyPreference.getInstance(context).setStringArrayPreflist2(context, jczqfav, "jczqfavoritos",
							fDataList);
				} else if (lotID == LOT_ID_BD) {
					// 存贮
					MyPreference.getInstance(context).setStringArrayPreflist2(context, bdfav, "bdfavoritos", fDataList);
				}

			} else {// 非正常格式
				List<Map<String, Object>> newDataList = new ArrayList<Map<String, Object>>();
				for (int i = 0; i < fList.size(); i++) {
					Map<String, Object> OldMap = fList.get(i);
					String oldmatchID = String.valueOf(OldMap.get("i1"));
					for (int j = 0; j < refreshList.size(); j++) {
						Map<String, Object> newMap = refreshList.get(j);
						// 赛事ID
						String newmatchID = String.valueOf(newMap.get("mid"));
						if (oldmatchID.equals(newmatchID)) {
							// 移除旧的
							// fList.remove(i);
							Map<String, Object> NewMap = new HashMap<String, Object>();
							// 筛选数据
							NewMap.put("i1", String.valueOf(OldMap.get("i1")));// 赛事ID
							NewMap.put("i2", String.valueOf(OldMap.get("i2")));// 赛事简称
							NewMap.put("i3", String.valueOf(OldMap.get("i3")));// 开赛时间
							NewMap.put("i4", String.valueOf(newMap.get("s")));// 状态
							NewMap.put("i5", String.valueOf(OldMap.get("i5")));// 主队
							NewMap.put("i6", String.valueOf(OldMap.get("i6")));// 主队红牌数
							NewMap.put("i7", String.valueOf(OldMap.get("i7")));// 主队黄牌数
							NewMap.put("i8", String.valueOf(OldMap.get("i8")));// 主队分数
							NewMap.put("i9", String.valueOf(OldMap.get("i9")));// 客队
							NewMap.put("i10", String.valueOf(OldMap.get("i10")));// 客队红牌数
							NewMap.put("i11", String.valueOf(OldMap.get("i11")));// 客队黄牌数
							NewMap.put("i12", String.valueOf(OldMap.get("i12")));// 客队分数
							NewMap.put("i13", String.valueOf(OldMap.get("i13")));// 半场比分
							NewMap.put("isCheck", Integer.parseInt(String.valueOf(OldMap.get("isCheck"))));
							NewMap.put("isLight", 0);
							// 加上新的
							// fList.add(i, NewMap);
							newDataList.add(NewMap);
						}
					}
				}
				// 复制newDataList给fDataList
				fDataList = new ArrayList<Map<String, Object>>(newDataList);
				changeFocusNum(fDataList.size());
				if (lotID == LOT_ID_JCZQ) {
					// 存贮
					MyPreference.getInstance(context).setStringArrayPreflist2(context, jczqfav, "jczqfavoritos",
							fDataList);
				} else if (lotID == LOT_ID_BD) {
					// 存贮
					MyPreference.getInstance(context).setStringArrayPreflist2(context, bdfav, "bdfavoritos", fDataList);
				}
			}
		}
	}

	/**
	 * 在某个状态按钮下，自动刷新的处理逻辑，不能全部调用刷新全部数据refNewestAllDataList，再筛选，会卡。
	 * 和当前显示的数据mDataList比较,减少运算量。 1全部：refreshList与mDataList比较，更新AllDataList,调用
	 * refNewestAllDataList() 2未开赛:
	 * refreshList与mDataList比较，a加入新的未开赛；b将未开赛转进行中的剔除 3进行中:
	 * refreshList与mDataList比较，a 将未开赛转进行中的加入;b 将进行中的比赛数据刷新；c将进行中转完场的剔除 4已完场
	 * :refreshList与mDataList比较，a 将进行中转完场的加入;b将已完场且服务器已剔除的剔除 5我的关注
	 * :refreshList与FavList(即fDataList)比较,将FavList数据实时刷新成refreshList中数据，若有ID一样
	 * 
	 * @param strResult
	 *            刷新数据(refreshList)
	 */
	private void doAutoRefresh(String strResult) {
		if (matchState == 0) {// 全部
			/** 不含ischeck字段的数据 */
			List<Map<String, Object>> nocheckList = new ArrayList<Map<String, Object>>();
			// 更新最新全部list
			// refNewestDataList(AllDataList);
			// 更新最新全部list并显示进球提示及声音
			refreshAllBtn(AllDataList);
			// 根据状态筛选
			if (seltitleslist != null && seltitleslist.size() != 0) {
				nocheckList.addAll(getHandleDataByShortList(matchState, seltitleslist));
			} else {
				nocheckList.addAll(getDataByState(matchState));
			}

			// 加上关注状态
			// 这样写可以调用list刷新方法notifyDataSetChanged生效,
			mDataList.clear();
			mDataList.addAll(AddCheck(nocheckList));
		} else if (matchState == 1) {// 未开赛
			if (seltitleslist != null && seltitleslist.size() != 0) {
				mDataList = getHandleDataByShortList(matchState, seltitleslist);
			}
			for (int i = 0; i < mDataList.size(); i++) {
				Map<String, Object> OldMap = mDataList.get(i);
				String oldmatchID = String.valueOf(OldMap.get("i1"));
				for (int j = 0; j < refreshList.size(); j++) {
					Map<String, Object> newMap = refreshList.get(j);
					// 赛事ID
					String newmatchID = String.valueOf(newMap.get("j1"));
					if (oldmatchID.equals(newmatchID)) {
						// 判断是否已经不是未开赛（转进行中），不是未开赛的剔除
						if (!String.valueOf(newMap.get("j1")).equals("未")
								|| !String.valueOf(newMap.get("j1")).equals("延")) {
							mDataList.remove(i);
						}
					}
				}
			}
		} else if (matchState == 2) {// 进行中
			// 如果有进球等变化需要更新flist
			if (strResult.contains("j1")) {
				// 更新最新flist
				refNewestDataList(fDataList);
			}
			// 实时刷新进行中
			refreshPresentBtn(strResult);
		} else if (matchState == 3) {// 已完场
			// 当有比分进球信息时需要更新全部数据列表,以便来回切换进行中和已完场数据都是最新
			if (mDataList.size() < refreshList.size() || strResult.contains("完") || strResult.contains("j1")) {
				/** 不含ischeck字段的数据 */
				List<Map<String, Object>> nocheckList = new ArrayList<Map<String, Object>>();
				// 更新最新全部list
				refNewestDataList(AllDataList);
				// 根据状态筛选
				// nocheckList = getDataByState(matchState);
				if (seltitleslist != null && seltitleslist.size() != 0) {
					nocheckList.addAll(getHandleDataByShortList(matchState, seltitleslist));
				} else {
					nocheckList.addAll(getDataByState(matchState));
				}
				// 加上关注状态
				// 这样写可以调用list刷新方法notifyDataSetChanged生效,
				mDataList.clear();
				mDataList.addAll(AddCheck(nocheckList));
				Log.d("doAutoRefresh", "已完场更新最新全部list");
			}
		} else if (matchState == 4) {// 我的关注

			/** 不含ischeck字段的数据 */
			List<Map<String, Object>> nocheckList = new ArrayList<Map<String, Object>>();
			// 更新最新全部list
			// refNewestDataList(AllDataList);
			// 更新最新全部list并显示进球提示及声音
			refreshAllBtn(AllDataList);
			// 根据状态筛选
			// nocheckList = getDataByState(matchState);
			if (seltitleslist != null && seltitleslist.size() != 0) {
				nocheckList.addAll(getHandleDataByShortList(matchState, seltitleslist));
			} else {
				nocheckList.addAll(getDataByState(matchState));
			}
			// 加上关注状态
			// 这样写可以调用list刷新方法notifyDataSetChanged生效,
			mDataList.clear();
			mDataList.addAll(AddCheck(nocheckList));

			// // 实时刷新我的关注
			// refreshFocusBtn(fDataList);
			// if(fDataList!=null){
			// Log.v("doAutoRefresh", "我的关注fDataList= " + fDataList.toString());
			// }
			// 如果我的关注中的比赛已经变成完，则存储
			// for (int i = 0; i < fDataList.size(); i++) {
			// if ("完".equals(String.valueOf(fDataList.get(i).get("i4")))) {
			// // 存贮我的关注的比赛
			// if(lotID==LOT_ID_JCZQ){
			// MyPreference.getInstance(context).setStringArrayPreflist2(context,
			// jczqfav,"jczqfavoritos", fDataList);
			// }else if(lotID==LOT_ID_BD){
			// MyPreference.getInstance(context).setStringArrayPreflist2(context,
			// bdfav,"bdfavoritos", fDataList);
			// }
			//
			// }
			// }
		}
	}

	/**
	 * /b 将进行中的比赛数据刷新；c将进行中转完场的剔除,显示声音提示及进球提示
	 * 
	 * @param strResult
	 *            网络刷新数据
	 */
	private void modifyINGChange(String strResult) {
		if (seltitleslist != null && seltitleslist.size() != 0) {
			mDataList = getHandleDataByShortList(matchState, seltitleslist);
		}
		// 将进行中的比赛数据刷新
		if (strResult.contains("j1")) {// 正常格式
			// 修改相同项ID的进行中的数据，刷新最新的数据
			for (int i = 0; i < mDataList.size(); i++) {
				Map<String, Object> OldMap = mDataList.get(i);
				String oldmatchID = String.valueOf(OldMap.get("i1"));
				for (int j = 0; j < refreshList.size(); j++) {
					Map<String, Object> newMap = refreshList.get(j);
					// 赛事ID
					String newmatchID = String.valueOf(newMap.get("j1"));
					// 修改刷新有变动的那个赛事
					if (oldmatchID.equals(newmatchID)) {
						// 移除旧的
						mDataList.remove(i);
						// 判断是否已经完场，已经完场的剔除
						if (!String.valueOf(newMap.get("j2")).equals("完")) {
							// 用新的数据取代旧的数据
							Map<String, Object> NewMap = new HashMap<String, Object>();
							// 筛选数据
							NewMap.put("i1", String.valueOf(OldMap.get("i1")));// 赛事ID
							NewMap.put("i2", String.valueOf(OldMap.get("i2")));// 赛事简称
							NewMap.put("i3", String.valueOf(OldMap.get("i3")));// 开赛时间
							NewMap.put("i4", String.valueOf(newMap.get("j2")));// 状态
							NewMap.put("i5", String.valueOf(OldMap.get("i5")));// 主队
							NewMap.put("i6", String.valueOf(newMap.get("j6")));// 主队红牌数
							NewMap.put("i7", String.valueOf(newMap.get("j7")));// 主队黄牌数
							NewMap.put("i8", String.valueOf(newMap.get("j3")));// 主队分数
							NewMap.put("i9", String.valueOf(OldMap.get("i9")));// 客队
							NewMap.put("i10", String.valueOf(newMap.get("j9")));// 客队红牌数
							NewMap.put("i11", String.valueOf(newMap.get("j10")));// 客队黄牌数
							NewMap.put("i12", String.valueOf(newMap.get("j4")));// 客队分数
							NewMap.put("i13", String.valueOf(newMap.get("j5")));// 半场比分
							NewMap.put("isCheck", Integer.parseInt(String.valueOf(OldMap.get("isCheck"))));
							NewMap.put("isLight", 0);
							// 加上新的
							mDataList.add(i, NewMap);
							// 弹出进球对话框和声音提示及红黄牌声音提示
							// 当进球时给出一个进球的弹窗，并且此场比赛的背景给变掉,进球声音的提示,红黄牌变动声音提示
							// showJinQiuTiShi();
							// j3主分 j4客分 旧i8 i12进球有变动时
							if ((!String.valueOf(newMap.get("j3")).equals(String.valueOf(OldMap.get("i8"))))
									|| (!String.valueOf(newMap.get("j4")).equals(String.valueOf(OldMap.get("i12"))))) {
								Log.e("modifyINGChange", "进球提示");
								// 弹出进球提示框
								LayoutInflater inflater = LayoutInflater.from(context);
								View view0 = inflater.inflate(R.layout.score_toasthint,
										(ViewGroup) findViewById(R.id.toast_layout_root));
								// 设置提示信息
								TextView name = (TextView) view0.findViewById(R.id.score_popuphint_saishiName);
								name.setText(String.valueOf(OldMap.get("i2")));
								TextView time = (TextView) view0.findViewById(R.id.score_popuphint_time);
								time.setText(String.valueOf(newMap.get("j2")));
								TextView hteam = (TextView) view0.findViewById(R.id.score_popuphint_hteam);
								// 名字过长截取9位
								String strhteam = String.valueOf(OldMap.get("i5"));
								String strH;
								if (strhteam.length() < 10) {
									strH = strhteam;
								} else {
									strH = strhteam.substring(0, 9);
								}
								hteam.setText(strH);
								TextView vteam = (TextView) view0.findViewById(R.id.score_popuphint_vteam);
								// 名字过长截取9位
								String strvteam = String.valueOf(OldMap.get("i9"));
								String strV;
								if (strvteam.length() < 10) {
									strV = strvteam;
								} else {
									strV = strvteam.substring(0, 9);
								}
								vteam.setText(strV);
								TextView hscore = (TextView) view0.findViewById(R.id.score_popuphint_hscore);
								hscore.setText(String.valueOf(newMap.get("j3")));
								TextView vscore = (TextView) view0.findViewById(R.id.score_popuphint_vscore);
								vscore.setText(String.valueOf(newMap.get("j4")));
								// 创建提示
								Toast toast = new Toast(context);
								toast.setDuration(Toast.LENGTH_LONG);
								toast.setView(view0);
								// app = (ApplicationBall) getApplication();
								int h = ApplicationData.getInstance().getTabHostHeight();
								Log.e("进球提示ing", "h= " + h);
								toast.setGravity(Gravity.CENTER | Gravity.BOTTOM, 0, h);
								toast.show();
								// Log.i("前未改变list背景", "mDataList= " +
								// mDataList.toString());
								// 此场比赛的背景给变掉
								Log.e("modifyINGChange", "改变list背景");
								for (int m = 0; m < mDataList.size(); m++) {
									if (m == i) {
										mDataList.get(m).put("isLight", 1);
									}
								}
								// Log.e("改变list背景", "mDataList= " +
								// mDataList.toString());
								// 声音提示
								if (MyPreference.getInstance(context).getSoundFlgJQ()) {
									playSounds(1, 0);
								}
							}
							// 红黄牌变动声音提示 旧 显示 主队红i6黄i7 客队红i10 黄i11 刷新
							// 主队红j6黄j7 客队红j9 黄j10
							if ((!String.valueOf(newMap.get("j6")).equals(String.valueOf(OldMap.get("i6"))))
									|| (!String.valueOf(newMap.get("j7")).equals(String.valueOf(OldMap.get("i7"))))
									|| (!String.valueOf(newMap.get("j9")).equals(String.valueOf(OldMap.get("i10"))))
									|| (!String.valueOf(newMap.get("j10")).equals(String.valueOf(OldMap.get("i11"))))) {
								Log.e("modifyINGChange", "红黄牌变动提示");
								// 播放声音
								if (MyPreference.getInstance(context).getSoundFlgHH()) {
									playSounds(2, 0);
								}
							}
						}
					}
				}
			}
		} else {// 非正常格式
			for (int i = 0; i < mDataList.size(); i++) {
				Map<String, Object> OldMap = mDataList.get(i);
				String oldmatchID = String.valueOf(OldMap.get("i1"));
				for (int j = 0; j < refreshList.size(); j++) {
					Map<String, Object> newMap = refreshList.get(j);
					// 赛事ID
					String newmatchID = String.valueOf(newMap.get("mid"));
					if (oldmatchID.contains(newmatchID)) {
						// 移除旧的
						mDataList.remove(i);
						// 判断是否已经完场，已经完场的剔除
						if (!String.valueOf(newMap.get("s")).equals("完")) {
							Map<String, Object> NewMap = new HashMap<String, Object>();
							// 筛选数据
							NewMap.put("i1", String.valueOf(OldMap.get("i1")));// 赛事ID
							NewMap.put("i2", String.valueOf(OldMap.get("i2")));// 赛事简称
							NewMap.put("i3", String.valueOf(OldMap.get("i3")));// 开赛时间
							NewMap.put("i4", String.valueOf(newMap.get("s")));// 状态
							NewMap.put("i5", String.valueOf(OldMap.get("i5")));// 主队
							NewMap.put("i6", String.valueOf(OldMap.get("i6")));// 主队红牌数
							NewMap.put("i7", String.valueOf(OldMap.get("i7")));// 主队黄牌数
							NewMap.put("i8", String.valueOf(OldMap.get("i8")));// 主队分数
							NewMap.put("i9", String.valueOf(OldMap.get("i9")));// 客队
							NewMap.put("i10", String.valueOf(OldMap.get("i10")));// 客队红牌数
							NewMap.put("i11", String.valueOf(OldMap.get("i11")));// 客队黄牌数
							NewMap.put("i12", String.valueOf(OldMap.get("i12")));// 客队分数
							NewMap.put("i13", String.valueOf(OldMap.get("i13")));// 半场比分
							NewMap.put("isCheck", Integer.parseInt(String.valueOf(OldMap.get("isCheck"))));
							NewMap.put("isLight", 0);
							// 加上新的
							mDataList.add(i, NewMap);
						}
					}
				}
			}
		}
	}

	/**
	 * 根据赛事状态筛选list
	 * 
	 * @param matchState
	 *            比赛状态
	 */
	private List<Map<String, Object>> getDataByState(int matchState) {
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		// 筛选数据
		if (matchState == 0) {// 全部
			// 复制AllDataList到临时list
			if (AllDataList != null) {
				// list = new ArrayList<Map<String, Object>>(AllDataList);
				list.clear();
				list.addAll(AllDataList);
			}
		} else if (matchState == 1) {// 未开赛
			// Log.e("getDataByState", "AllDataList= "+AllDataList.toString());
			// 复制AllDataList到临时list tempList
			List<Map<String, Object>> tempList = new ArrayList<Map<String, Object>>();
			if (AllDataList != null) {
				// tempList = new ArrayList<Map<String, Object>>(AllDataList);
				tempList.clear();
				tempList.addAll(AllDataList);
			}
			// Log.e("getDataByState", "tempList= "+tempList.toString());
			if (tempList != null && tempList.size() != 0) {
				List<Map<String, Object>> NewList = new ArrayList<Map<String, Object>>();
				for (int i = 0; i < tempList.size(); i++) {
					Map<String, Object> OldMap = tempList.get(i);
					String strState = String.valueOf(OldMap.get("i4"));
					if (strState.equals("未") || strState.equals("延") || strState.equals("推迟开赛")) {
						Map<String, Object> NewMap = new HashMap<String, Object>();
						NewMap.put("i4", strState);
						NewMap.put("i1", String.valueOf(OldMap.get("i1")));
						NewMap.put("i2", String.valueOf(OldMap.get("i2")));
						NewMap.put("i3", String.valueOf(OldMap.get("i3")));
						NewMap.put("i5", String.valueOf(OldMap.get("i5")));
						NewMap.put("i6", String.valueOf(OldMap.get("i6")));
						NewMap.put("i7", String.valueOf(OldMap.get("i7")));
						NewMap.put("i8", String.valueOf(OldMap.get("i8")));
						NewMap.put("i9", String.valueOf(OldMap.get("i9")));
						NewMap.put("i10", String.valueOf(OldMap.get("i10")));
						NewMap.put("i11", String.valueOf(OldMap.get("i11")));
						NewMap.put("i12", String.valueOf(OldMap.get("i12")));
						NewMap.put("i13", String.valueOf(OldMap.get("i13")));
						NewMap.put("isCheck", Integer.parseInt(String.valueOf(OldMap.get("isCheck"))));
						NewMap.put("isLight", 0);
						NewList.add(NewMap);
					}
				}
				// list = new ArrayList<Map<String, Object>>(NewList);
				list.clear();
				list.addAll(NewList);
			}
		} else if (matchState == 2) {// 进行中
			// Log.e("getDataByState", "AllDataList= "+AllDataList.toString());
			// 复制AllDataList到临时list tempList
			List<Map<String, Object>> tempList = new ArrayList<Map<String, Object>>();
			if (AllDataList != null) {
				// tempList = new ArrayList<Map<String, Object>>(AllDataList);
				tempList.clear();
				tempList.addAll(AllDataList);
			}
			// Log.e("getDataByState", "tempList= "+tempList.toString());
			if (tempList != null && tempList.size() != 0) {
				List<Map<String, Object>> NewList = new ArrayList<Map<String, Object>>();
				for (int i = 0; i < tempList.size(); i++) {
					Map<String, Object> OldMap = tempList.get(i);
					String strState = String.valueOf(OldMap.get("i4"));
					if (!strState.equals("未") && (!strState.equals("延") && (!strState.equals("推迟开赛")))
							&& (!strState.equals("完")) && (!strState.equals("弃赛")) && (!strState.equals("取消"))) {
						Map<String, Object> NewMap = new HashMap<String, Object>();
						NewMap.put("i4", strState);
						NewMap.put("i1", String.valueOf(OldMap.get("i1")));
						NewMap.put("i2", String.valueOf(OldMap.get("i2")));
						NewMap.put("i3", String.valueOf(OldMap.get("i3")));
						NewMap.put("i5", String.valueOf(OldMap.get("i5")));
						NewMap.put("i6", String.valueOf(OldMap.get("i6")));
						NewMap.put("i7", String.valueOf(OldMap.get("i7")));
						NewMap.put("i8", String.valueOf(OldMap.get("i8")));
						NewMap.put("i9", String.valueOf(OldMap.get("i9")));
						NewMap.put("i10", String.valueOf(OldMap.get("i10")));
						NewMap.put("i11", String.valueOf(OldMap.get("i11")));
						NewMap.put("i12", String.valueOf(OldMap.get("i12")));
						NewMap.put("i13", String.valueOf(OldMap.get("i13")));
						NewMap.put("isCheck", Integer.parseInt(String.valueOf(OldMap.get("isCheck"))));
						NewMap.put("isLight", 0);
						NewList.add(NewMap);
					}
				}
				// list = new ArrayList<Map<String, Object>>(NewList);
				list.clear();
				list.addAll(NewList);
			}
		} else if (matchState == 3) {// 已完场
			// Log.e("getDataByState", "AllDataList= "+AllDataList.toString());
			// 复制AllDataList到临时list tempList
			List<Map<String, Object>> tempList = new ArrayList<Map<String, Object>>();
			if (AllDataList != null) {
				// tempList = new ArrayList<Map<String, Object>>(AllDataList);
				tempList.clear();
				tempList.addAll(AllDataList);
			}
			// Log.e("getDataByState", "tempList= "+tempList.toString());
			if (tempList != null && tempList.size() != 0) {
				List<Map<String, Object>> NewList = new ArrayList<Map<String, Object>>();
				for (int i = 0; i < tempList.size(); i++) {
					Map<String, Object> OldMap = tempList.get(i);
					String strState = String.valueOf(OldMap.get("i4"));
					if (strState.equals("完") || strState.equals("弃赛") || strState.equals("取消")) {
						Map<String, Object> NewMap = new HashMap<String, Object>();
						NewMap.put("i4", strState);
						NewMap.put("i1", String.valueOf(OldMap.get("i1")));
						NewMap.put("i2", String.valueOf(OldMap.get("i2")));
						NewMap.put("i3", String.valueOf(OldMap.get("i3")));
						NewMap.put("i5", String.valueOf(OldMap.get("i5")));
						NewMap.put("i6", String.valueOf(OldMap.get("i6")));
						NewMap.put("i7", String.valueOf(OldMap.get("i7")));
						NewMap.put("i8", String.valueOf(OldMap.get("i8")));
						NewMap.put("i9", String.valueOf(OldMap.get("i9")));
						NewMap.put("i10", String.valueOf(OldMap.get("i10")));
						NewMap.put("i11", String.valueOf(OldMap.get("i11")));
						NewMap.put("i12", String.valueOf(OldMap.get("i12")));
						NewMap.put("i13", String.valueOf(OldMap.get("i13")));
						NewMap.put("isCheck", Integer.parseInt(String.valueOf(OldMap.get("isCheck"))));
						NewMap.put("isLight", 0);
						NewList.add(NewMap);
					}
				}
				// list = new ArrayList<Map<String, Object>>(NewList);
				list.clear();
				list.addAll(NewList);
			}
		} else if (matchState == 4) {// 我的关注
			// 从保存的本地文件中读取
			FaviList = new ArrayList<Map<String, Object>>();
			if (lotID == LOT_ID_JCZQ) {
				FaviList = MyPreference.getInstance(context).getStringArrayPreflist2(context, jczqfav, "jczqfavoritos");
			} else if (lotID == LOT_ID_BD) {
				FaviList = MyPreference.getInstance(context).getStringArrayPreflist2(context, bdfav, "bdfavoritos");
			}

			// fDataList第一次使用FaviList，其他使用已经有的
			if (isFirst) {
				fDataList = new ArrayList<Map<String, Object>>(FaviList);
				// fDataList.clear();
				// fDataList.addAll(FaviList);
				isFirst = false;
			}
			// 比较FaviList和fDataList大小，如果不一样则更新fDataList,说明用户做了添加或删除关注操作
			if (FaviList.size() != fDataList.size()) {
				fDataList = new ArrayList<Map<String, Object>>(FaviList);
				changeFocusNum(fDataList.size());
			}
			// 否则从服务器数据中更新我的关注赛事；增加已完场的情况判断分支
			refNewestDataList(fDataList);
			list = new ArrayList<Map<String, Object>>(fDataList);
		}
		// 重新判断我的关注数量，在48小时判断和当前服务器数据是否包含赛事判断之后执行
		List<Map<String, Object>> FaviInitList = new ArrayList<Map<String, Object>>();
		if (lotID == LOT_ID_JCZQ) {
			// 从保存的本地文件中读取
			FaviInitList = MyPreference.getInstance(context).getStringArrayPreflist2(context, jczqfav, "jczqfavoritos");
		} else if (lotID == LOT_ID_BD) {
			FaviInitList = MyPreference.getInstance(context).getStringArrayPreflist2(context, bdfav, "bdfavoritos");
		}
		changeFocusNum(FaviInitList.size());
		return list;
	}

	/**
	 * 从ListView的数据集合中找到要修改的那条数据，加上check,修改它，
	 * 
	 * @param list
	 *            网络数据
	 */
	private List<Map<String, Object>> AddCheck(List<Map<String, Object>> list) {
		// Log.d("AddCheck", "list= " + list.toString());
		List<Map<String, Object>> Favolist = new ArrayList<Map<String, Object>>();
		// 从保存的本地文件中读取
		// Favolist =
		// MyPreference.getInstance(context).getStringArrayPref2(context,
		// "favoritos");
		if (lotID == LOT_ID_JCZQ) {
			Favolist = MyPreference.getInstance(context).getStringArrayPreflist2(context, jczqfav, "jczqfavoritos");
		} else if (lotID == LOT_ID_BD) {
			Favolist = MyPreference.getInstance(context).getStringArrayPreflist2(context, bdfav, "bdfavoritos");
		}
		if (Favolist != null && list != null) {
			// 如果收藏夹没有，那么所有选项都未被选中
			if (Favolist.size() == 0) {
				for (int i = 0; i < list.size(); i++) {
					list.get(i).put("isCheck", 0);
				}
			}
			// 如果收藏夹有，那么相同选项都被选中
			else {
				// Log.d("AddCheck", "Favlist= " + Favlist.toString());
				// 首先初始化isCheck
				for (int i = 0; i < list.size(); i++) {
					list.get(i).put("isCheck", 0);
				}
				// 修改选中的关注
				for (int i = 0; i < list.size(); i++) {
					Map<String, Object> OldMap = list.get(i);
					// Log.i("AddCheck", "OldMap= " + OldMap.toString());
					String oldmatchID = String.valueOf(OldMap.get("i1"));
					for (int j = 0; j < Favolist.size(); j++) {
						Map<String, Object> newMap = Favolist.get(j);
						// Log.v("AddCheck", "newMap= " + newMap.toString());
						// 赛事ID
						String newmatchID = String.valueOf(newMap.get("i1"));
						if (oldmatchID.equals(newmatchID)) {
							// Log.i("AddCheck", "if put 1 i= " + i +
							// " oldmatchID= " + oldmatchID + " newmatchID= " +
							// newmatchID);
							list.get(i).put("isCheck", 1);
						}
					}
				}
			}
		}
		// Log.e("AddCheck", "list= " + list.toString());
		return list;
	}

	/**
	 * 显示比分list;根据赛事状态,关注显示
	 * 
	 * @param matchState
	 *            比赛状态
	 */
	public void showSList(int matchState) {
		/** 不含ischeck字段的数据 */
		List<Map<String, Object>> nocheckList = new ArrayList<Map<String, Object>>();
		// 更新最新全部list
		refNewestDataList(AllDataList);
		// 根据状态筛选
		// nocheckList = getDataByState(matchState);
		if (seltitleslist != null && seltitleslist.size() != 0) {
			nocheckList.addAll(getHandleDataByShortList(matchState, seltitleslist));
		} else {
			nocheckList.addAll(getDataByState(matchState));
		}
		if (matchState != 4) {
			// 加上关注状态
			mDataList = new ArrayList<Map<String, Object>>();
			mDataList.clear();
			mDataList.addAll(AddCheck(nocheckList));
			if (mDataList != null) {
				// 初始化不高亮
				for (int i = 0; i < mDataList.size(); i++) {
					mDataList.get(i).put("isLight", 0);
				}
				// Log.v("showSList", "mDataList= " + mDataList.toString());
				scoreAdapter = new ScoreOnlineListAdapter(context, mDataList, matchState, lotID);
				lv_score_list.setAdapter(scoreAdapter);
			}
		} else {
			// 加上关注状态
			// fDataList = AddCheck(nocheckList);
			fDataList = new ArrayList<Map<String, Object>>();
			fDataList.clear();
			fDataList.addAll(AddCheck(nocheckList));
			if (fDataList != null && AllDataList != null) {
				if (isFirst2) {
					// 更新最新的我的关注,将全部数据中key（赛事ID）和关注赛事中赛事ID一样的取出放到newDataList，原fDataList清空内容用newDataList
					List<Map<String, Object>> newDataList = new ArrayList<Map<String, Object>>();
					for (int i = 0; i < fDataList.size(); i++) {
						Map<String, Object> OldMap = fDataList.get(i);
						String oldmatchID = String.valueOf(OldMap.get("i1"));
						for (int j = 0; j < AllDataList.size(); j++) {
							Map<String, Object> newMap = AllDataList.get(j);
							// 赛事ID
							String newmatchID = String.valueOf(newMap.get("i1"));
							if (oldmatchID.equals(newmatchID)) {
								// // 移除旧的
								// fDataList.remove(i);
								Map<String, Object> NewMap = new HashMap<String, Object>();
								// 筛选数据
								NewMap.put("i1", String.valueOf(newMap.get("i1")));// 赛事ID
								NewMap.put("i2", String.valueOf(newMap.get("i2")));// 赛事简称
								NewMap.put("i3", String.valueOf(newMap.get("i3")));// 开赛时间
								NewMap.put("i4", String.valueOf(newMap.get("i4")));// 状态
								NewMap.put("i5", String.valueOf(newMap.get("i5")));// 主队
								NewMap.put("i6", String.valueOf(newMap.get("i6")));// 主队红牌数
								NewMap.put("i7", String.valueOf(newMap.get("i7")));// 主队黄牌数
								NewMap.put("i8", String.valueOf(newMap.get("i8")));// 主队分数
								NewMap.put("i9", String.valueOf(newMap.get("i9")));// 客队
								NewMap.put("i10", String.valueOf(newMap.get("i10")));// 客队红牌数
								NewMap.put("i11", String.valueOf(newMap.get("i11")));// 客队黄牌数
								NewMap.put("i12", String.valueOf(newMap.get("i12")));// 客队分数
								NewMap.put("i13", String.valueOf(newMap.get("i13")));// 半场比分
								NewMap.put("isCheck", Integer.parseInt(String.valueOf(OldMap.get("isCheck"))));
								NewMap.put("isLight", 0);
								// 加上新的
								// fDataList.add(i, NewMap);
								newDataList.add(NewMap);
							}
						}
					}
					// 复制newDataList给fDataList
					fDataList = new ArrayList<Map<String, Object>>(newDataList);
					changeFocusNum(fDataList.size());
					if (lotID == LOT_ID_JCZQ) {
						// 存贮
						MyPreference.getInstance(context).setStringArrayPreflist2(context, jczqfav, "jczqfavoritos",
								fDataList);
					} else if (lotID == LOT_ID_BD) {
						// 存贮
						MyPreference.getInstance(context).setStringArrayPreflist2(context, bdfav, "bdfavoritos",
								fDataList);
					}
					isFirst2 = false;
				}
				// 初始化不高亮
				for (int i = 0; i < fDataList.size(); i++) {
					fDataList.get(i).put("isLight", 0);
				}
				scoreAdapter = new ScoreOnlineListAdapter(context, fDataList, matchState, lotID);
				lv_score_list.setAdapter(scoreAdapter);
			}
		}
	}

	/**
	 * 因为第一次从服务器获取的数据不是最新的，先将第一次获取的数据存储，第二次请求的返回数据与第一次比较，将第一次数据更新成最新的，
	 * 再在listview中显示
	 * 
	 * @param strResult
	 */
	public void showFirstAutoRefresh(String strResult) {
		// 获取刷新数据
		refreshList = getRefreshList(strResult);
		// Log.v("showFirstAutoRefresh", "refreshList= " +
		// refreshList.toString());
		// 加入是否高亮字段
		for (int i = 0; i < refreshList.size(); i++) {
			refreshList.get(i).put("isLight", 0);
		}
		/** 不含ischeck字段的数据 */
		List<Map<String, Object>> nocheckList = new ArrayList<Map<String, Object>>();
		// 更新最新全部list
		if (refreshList != null && refreshList.size() != 0) {
			refNewestDataList(AllDataList);
		}
		// 根据状态筛选
		nocheckList.addAll(getDataByState(matchState));
		mDataList = new ArrayList<Map<String, Object>>();
		mDataList.clear();
		mDataList.addAll(AddCheck(nocheckList));
		// 因为第一次从服务器获取的数据不是最新的，先将第一次获取的数据存储，第二次请求的返回数据与第一次比较doAutoRefresh，将第一次数据更新成最新的，再在listview中显示
		if (mDataList != null) {
			scoreAdapter = new ScoreOnlineListAdapter(context, mDataList, matchState, lotID);
			lv_score_list.setAdapter(scoreAdapter);
		}
	}

	/**
	 * 处理网络返回刷新数据及显示listview视图
	 * 从ListView的数据集合中找到要修改的那条数据，修改它，然后用adapter.notifyDataSetChanged();
	 * 通知listview刷新就可以实现局部刷新，因为你的修改了数据集的一条数据 ; 比较两个list，找出ID一样的，用新值替换旧的
	 * 
	 * @param strResult
	 *            [{j4=0, j5=4:0, j2=50, j3=4, j8=0, j9=0, j6=0, j7=0, j10=0,
	 *            j11=0, j1=3878531}] [{s=51, mid=3878531}]
	 */
	public void showAutoRefresh(String strResult) {
		// 获取刷新数据
		refreshList = getRefreshList(strResult);
		// 加入是否高亮字段
		for (int i = 0; i < refreshList.size(); i++) {
			refreshList.get(i).put("isLight", 0);
		}
		// 更新全部数据再筛选思路会降低效率
		// refNewestAllDataList();
		// mDataList=getDataByState(matchState);
		doAutoRefresh(strResult);
		// 局部刷新listview
		scoreAdapter.notifyDataSetChanged();
	}

	/**
	 * 手动刷新数据，更新全部数据
	 * 
	 * @param strResult
	 */
	public void showShouDongRefresh(String strResult) {
		// 获取刷新数据
		refreshList = getRefreshList(strResult);
		// 加入是否高亮字段
		for (int i = 0; i < refreshList.size(); i++) {
			refreshList.get(i).put("isLight", 0);
		}
		// 更新全部数据
		refNewestDataList(AllDataList);
		// 筛选数据
		mDataList = getDataByState(matchState);
		scoreAdapter.notifyDataSetChanged();
	}

	/**
	 * 获取最新刷新数据，网络刷新结果数据json转list
	 * 
	 * @param strResult
	 *            网络结果数据json
	 * @return List
	 */
	private List<Map<String, Object>> getRefreshList(String strResult) {
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		if (!strResult.contains("LastTime")) {
			// 获取非正常格式的刷新数据
			list = ConvertJsonToList.getList(strResult);
		} else {
			try {
				JSONTokener jsonParser = new JSONTokener(strResult);
				JSONObject js = (JSONObject) jsonParser.nextValue();
				LastTime = String.valueOf(js.getString("LastTime"));
				// Log.v("getData", "LastTime= " + LastTime);
				list = ConvertJsonToList.getList(js.getString("ZqMobileLastMatch"));
			} catch (JSONException ex) {
				// 异常处理代码
				// ex.printStackTrace();
			}
		}
		return list;
	}

	/**
	 * 筛选按钮获取赛事名称及对应的个数数组
	 */
	private void dFilterNameAndNumber() {
		// List<Map<String, Object>> NewList = new ArrayList<Map<String,
		// Object>>();
		// 刷新全部list数据,根据全部数据，筛选赛事简称
		refNewestDataList(AllDataList);
		// NewList = getDataByState(matchState);
		// 存放数组中
		if (AllDataList != null && AllDataList.size() != 0) {
			List<String> mylist = new ArrayList<String>();
			for (int i = 0; i < AllDataList.size(); i++) {
				Map<String, Object> OldMap = AllDataList.get(i);
				String strName = String.valueOf(OldMap.get("i2"));
				// 筛选数据
				mylist.add(strName);
			}
			// 获取赛事名称及数量数组
			Map<String, Integer> newmap = new HashMap<String, Integer>();
			for (String item : mylist) {
				if (newmap.containsKey(item)) {
					newmap.put(item, newmap.get(item).intValue() + 1);
				} else {
					newmap.put(item, new Integer(1));
				}
			}
			Iterator<String> keys = newmap.keySet().iterator();
			titleslist = new ArrayList<String>();
			List<Integer> numslist = new ArrayList<Integer>();
			while (keys.hasNext()) {
				String key = keys.next();
				titleslist.add(key);
				numslist.add(newmap.get(key).intValue());
			}
			// System.out.println("titleslist= " + titleslist.toString());
			// System.out.println("numslist= " + numslist.toString());
			// list转string数组
			titles = titleslist.toArray(new String[titleslist.size()]);
			// for (String s : titles) {
			// System.out.println(s);
			// }
			// 获取个数
			Integer tmpInteger[] = new Integer[numslist.size()];
			nums = new int[numslist.size()];
			numslist.toArray(tmpInteger);
			for (int i = 0; i < tmpInteger.length; i++) {
				nums[i] = tmpInteger[i].intValue();
				// System.out.println(nums[i]);
			}
		}
	}

	/**
	 * 根据赛事状态和简称,取得 当前显示的list的数据列表
	 * 
	 * @param matchState
	 *            赛事状态
	 * @param seltitleslist
	 *            选中的赛事简称
	 */
	private List<Map<String, Object>> getHandleDataByShortList(int matchState, List<String> seltitleslist) {
		List<Map<String, Object>> NList = new ArrayList<Map<String, Object>>();
		NList = getDataByState(matchState);
		// Log.v("getHandleDataByShortList", "NList= " + NList.toString());
		if (NList != null && NList.size() != 0) {
			List<Map<String, Object>> NewList = new ArrayList<Map<String, Object>>();
			for (int i = 0; i < NList.size(); i++) {
				Map<String, Object> OldMap = NList.get(i);
				// 赛事简称
				String mShort = String.valueOf(OldMap.get("i2"));
				if (seltitleslist.contains(mShort)) {
					Map<String, Object> NewMap = new HashMap<String, Object>();
					// 筛选数据
					NewMap.put("i1", String.valueOf(OldMap.get("i1")));
					NewMap.put("i2", mShort);
					NewMap.put("i4", String.valueOf(OldMap.get("i4")));
					NewMap.put("i3", String.valueOf(OldMap.get("i3")));
					NewMap.put("i5", String.valueOf(OldMap.get("i5")));
					NewMap.put("i6", String.valueOf(OldMap.get("i6")));
					NewMap.put("i7", String.valueOf(OldMap.get("i7")));
					NewMap.put("i8", String.valueOf(OldMap.get("i8")));
					NewMap.put("i9", String.valueOf(OldMap.get("i9")));
					NewMap.put("i10", String.valueOf(OldMap.get("i10")));
					NewMap.put("i11", String.valueOf(OldMap.get("i11")));
					NewMap.put("i12", String.valueOf(OldMap.get("i12")));
					NewMap.put("i13", String.valueOf(OldMap.get("i13")));
					NewMap.put("isCheck", Integer.parseInt(String.valueOf(OldMap.get("isCheck"))));
					NewList.add(NewMap);
				}
			}
			mDataList = NewList;
		} else {
			if (mDataList != null) {
				mDataList.clear();
			}
		}
		return mDataList;
	}

	/**
	 * 根据赛事状态和简称显示list
	 * 
	 * @param matchState
	 *            赛事状态
	 * @param seltitleslist
	 *            选中的赛事简称
	 */
	private void handleDataByShort(int matchState, List<String> seltitleslist) {
		List<Map<String, Object>> NList = new ArrayList<Map<String, Object>>();
		NList = getDataByState(matchState);
		// Log.v("handleDataByShort", "NList= " + NList.toString());
		if (NList != null && NList.size() != 0) {
			List<Map<String, Object>> NewList = new ArrayList<Map<String, Object>>();
			for (int i = 0; i < NList.size(); i++) {
				Map<String, Object> OldMap = NList.get(i);
				// 赛事简称
				String mShort = String.valueOf(OldMap.get("i2"));
				if (seltitleslist.contains(mShort)) {
					Map<String, Object> NewMap = new HashMap<String, Object>();
					// 筛选数据
					NewMap.put("i1", String.valueOf(OldMap.get("i1")));
					NewMap.put("i2", mShort);
					NewMap.put("i4", String.valueOf(OldMap.get("i4")));
					NewMap.put("i3", String.valueOf(OldMap.get("i3")));
					NewMap.put("i5", String.valueOf(OldMap.get("i5")));
					NewMap.put("i6", String.valueOf(OldMap.get("i6")));
					NewMap.put("i7", String.valueOf(OldMap.get("i7")));
					NewMap.put("i8", String.valueOf(OldMap.get("i8")));
					NewMap.put("i9", String.valueOf(OldMap.get("i9")));
					NewMap.put("i10", String.valueOf(OldMap.get("i10")));
					NewMap.put("i11", String.valueOf(OldMap.get("i11")));
					NewMap.put("i12", String.valueOf(OldMap.get("i12")));
					NewMap.put("i13", String.valueOf(OldMap.get("i13")));
					NewMap.put("isCheck", Integer.parseInt(String.valueOf(OldMap.get("isCheck"))));
					NewList.add(NewMap);
				}
			}
			mDataList = NewList;
		}
		// Log.i("handleDataByShort", "mDataList= " + mDataList.toString());
		scoreAdapter = new ScoreOnlineListAdapter(context, mDataList, matchState, lotID);
		lv_score_list.setAdapter(scoreAdapter);
	}

	/**
	 * 删除我的关注当前选中项
	 * 
	 * @param currentItem
	 *            当前选中项
	 */
	public void listRemove(int currentItem) {
		// 接口继承
		scoreAdapter.notifyDataSetChanged();
	}

	private void setBtnOnClick(final int btnId) {
		Button btn = (Button) findViewById(btnId);
		btn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				try {
					matchState = getmatchState(btnId);
					showSList(matchState);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					// e.printStackTrace();
				}
			}
		});
	}

	/**
	 * 获取比赛状态，及改变按钮背景
	 * 
	 * @param btnId
	 * @return
	 */
	public int getmatchState(int btnId) {
		// 恢复默认
		bt_all.setEnabled(true);
		bt_unopen.setEnabled(true);
		bt_present.setEnabled(true);
		bt_done.setEnabled(true);
		bt_focus.setEnabled(true);
		// bt_all.setTextColor(context.getResources().getColor(R.color.buy_jxxh_fontcolor_qianhui));
		// bt_unopen.setTextColor(context.getResources().getColor(R.color.buy_jxxh_fontcolor_qianhui));
		// bt_present.setTextColor(context.getResources().getColor(R.color.buy_jxxh_fontcolor_qianhui));
		// bt_done.setTextColor(context.getResources().getColor(R.color.buy_jxxh_fontcolor_qianhui));
		// bt_focus.setTextColor(context.getResources().getColor(R.color.buy_jxxh_fontcolor_qianhui));
		switch (btnId) {
		case R.id.score_bt_all:
			matchState = 0;
			bt_all.setEnabled(false);
			// bt_all.setTextColor(context.getResources().getColor(R.color.buy_jxxh_fontcolor_qianhui));
			break;
		case R.id.score_bt_unopen:
			matchState = 1;
			bt_unopen.setEnabled(false);
			// bt_unopen.setTextColor(context.getResources().getColor(R.color.white));
			break;
		case R.id.score_present:
			matchState = 2;
			bt_present.setEnabled(false);
			// bt_present.setTextColor(context.getResources().getColor(R.color.white));
			break;
		case R.id.score_bt_done:
			matchState = 3;
			bt_done.setEnabled(false);
			// bt_done.setTextColor(context.getResources().getColor(R.color.white));
			break;
		case R.id.score_bt_focus:
			matchState = 4;
			bt_focus.setEnabled(false);
			// bt_focus.setTextColor(context.getResources().getColor(R.color.white));
			break;
		}
		return matchState;
	}

	/**
	 * 即时改变关注数量
	 * 
	 * @param foucs
	 *            我的关注条数
	 */
	public static void changeFocusNum(int foucs) {
		if (foucs == 0) {
			score_tv_focusNum.setVisibility(View.GONE);
		} else {
			score_tv_focusNum.setVisibility(View.VISIBLE);
			score_tv_focusNum.setText("" + foucs);
		}
	}

	/**
	 * 状态重置初始化
	 */
	public void reset() {
		// 初始状态重置
		if (AllDataList != null) {
			AllDataList.clear();
		}
		if (mDataList != null) {
			mDataList.clear();
		}
		isFirst = true;
		isFirst2 = true;
		isFirst4 = true;
		// 清除筛选按钮弹出框前次彩种的选中状态，初始化全部选中
		dilog_btn_select_status.clear();
		// 清除筛选按钮前次彩种的列表所有赛事
		if (adapter != null)
			adapter.clearseltitleslist();
		// 清除筛选按钮数据
		titles = null;
		nums = null;
		if (titleslist != null) {
			titleslist.clear();
		}
		if (seltitleslist != null) {
			seltitleslist.clear();
		}
	}

	/**
	 * 菜单玩法按钮事件
	 * 
	 * @param btnId
	 */
	private void setBtnOnClickTopMenu(final int btnId) {
		Button btn = (Button) menutypeview.findViewById(btnId);
		btn.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				try {
					menu_popupWindow.dismiss();
					setOrderFieldMenu(btnId);
					// 发送不同彩种网络请求
					TextView top_title_tvplaytype = (TextView) findViewById(R.id.top_title_tvplaytype);
					top_title_tvplaytype.setText(strLot);
					reset();
					setupData();
				} catch (Exception e) {
					// TODO Auto-generated catch block
					// e.printStackTrace();
				}
			}
		});
	}

	/**
	 * 获取玩法及改变按钮背景
	 * 
	 * @param btnId
	 */
	public void setOrderFieldMenu(int btnId) {
		// 恢复默认
		((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button01)).setEnabled(true);
		((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button02)).setEnabled(true);
		switch (btnId) {
		case R.id.buy_new11x5_topmenulink_Button01:
			lotID = 90;
			strLot = "竞彩足球";
			((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button01)).setEnabled(false);
			break;
		case R.id.buy_new11x5_topmenulink_Button02:
			lotID = 45;
			strLot = "北京单场";
			((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button02)).setEnabled(false);
			break;
		}
	}

	/**
	 * TitleBar标题栏
	 */
	public void titleBar() {
		// Title信息(返回+Title)
		Button back = (Button) findViewById(R.id.top_title_back);
		back.getBackground().setAlpha(255);// 透明度0~255透明度值 ，值越小越透明
		back.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				EventManager.getInstance().onEvent(EventType.EV_UI_FRM_MAIN_JUMP, FrmWorkStatus.MAINHOME);
			}
		});

		final RelativeLayout top_title_rlplaytype = (RelativeLayout) findViewById(R.id.top_title_rlplaytype);
		top_title_rlplaytype.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				try {
					LayoutInflater inflater = LayoutInflater.from(context);
					menutypeview = inflater.inflate(R.layout.score_topmenulink, null);
					menu_popupWindow = new PopupWindow(menutypeview, LayoutParams.WRAP_CONTENT,
							LayoutParams.WRAP_CONTENT);
					menu_popupWindow.setBackgroundDrawable(new BitmapDrawable());
					menu_popupWindow.showAtLocation(menutypeview, Gravity.CENTER | Gravity.TOP, 0, 0);
					menu_popupWindow.showAsDropDown(top_title_rlplaytype);
					menutypeview.setOnClickListener(new View.OnClickListener() {
						public void onClick(View v) {
							// TODO Auto-generated method stub
							menu_popupWindow.dismiss();
						}
					});
					setBtnOnClickTopMenu(R.id.buy_new11x5_topmenulink_Button01);
					setBtnOnClickTopMenu(R.id.buy_new11x5_topmenulink_Button02);
					// select first button
					if (lotID == 90) {
						((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button01)).setEnabled(false);
					} else if (lotID == 45) {
						((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button02)).setEnabled(false);
					}
				} catch (Exception e) {
					// TODO Auto-generated catch block
					// e.printStackTrace();
				}
			}
		});
		// 筛选
		Button filter = (Button) findViewById(R.id.score_bt_filter);
		filter.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (!isLoading) {
					Context cxt = context;
					// CustomfilterDialog cd = new CustomfilterDialog(context);
					CustomfilterDialog cd = new CustomfilterDialog(cxt, R.style.saishiDialog, dilog_btn_select_status);
					cd.setCancelable(false);
					cd.show();
				}
			}
		});
		// 刷新
		Button refresh = (Button) findViewById(R.id.score_refresh);
		refresh.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				ScoreMainActivity.this.finish();
			}
		});
	}

	/**
	 * 播放声音
	 * 
	 * @param sound
	 *            类型
	 * @param number
	 *            几次
	 */
	public void playSounds(int sound, int number) {
		AudioManager am = (AudioManager) context.getSystemService(context.AUDIO_SERVICE);
		float audioMaxVolumn = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
		float audioCurrentVolumn = am.getStreamVolume(AudioManager.STREAM_MUSIC);
		float volumnRatio = audioCurrentVolumn / audioMaxVolumn;

		sp.play(spMap.get(sound), volumnRatio, volumnRatio, 1, number, 1);
	}

	/**
	 * 刷新获取数据,自动刷新不显示对话框
	 * 
	 * @author Administrator
	 * 
	 */
	public class autoRefreshTask extends AsyncTask<String, Integer, String> {
		String action;

		// 构造方法
		public autoRefreshTask() {
			// TODO Auto-generated constructor stub
			super();
		}

		@Override
		protected void onPreExecute() {
		}

		protected String doInBackground(String... paramsArr) {
			// 处理后台执行的任务，在后台线程执行
			String strResult = null;
			action = paramsArr[1];
			// 获取请求返回值
			strResult = GetRequestParams.getScoreRequestResult(paramsArr[0], action, context);
			// Log.i("MyTask doInBackground", "action= " + action +
			// ", strResult= " + strResult);
			// 获取请求返回值
			return strResult;
		}

		// 4.完成后台任务
		protected void onPostExecute(String result) {
			try {
				if (result != null) {
					// 服务器不同格式判断
					if (result.contains("Code")) {
					} else {
						if (action.equals("mobilpartmatchs")) {
							// 仅首次进入页面执行
							if (isFirst4) {
								showFirstAutoRefresh(result);
								isFirst4 = false;
							}
							if (!result.equals("[]")) {// 有最新数据
								// 刷新
								showAutoRefresh(result);
							}
						}
					}
				} else {
					if (!isFirstShowTip) {
						isFirstShowTip = true;
						Toast.makeText(context, context.getString(R.string.problem_01), Toast.LENGTH_LONG).show();
					}
				}
				// score_lv_loading.setVisibility(View.GONE);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				// e.printStackTrace();
			}
		}
	}

	/**
	 * 刷新获取数据,手动刷新显示对话框
	 * 
	 * @author Administrator
	 * 
	 */
	public class shouDongRefresh extends AsyncTask<String, Integer, String> {
		String action;

		// ShowTipDialog showdialog = new ShowTipDialog();

		// 构造方法
		public shouDongRefresh() {
			super();
		}

		// 1.准备运行
		protected void onPreExecute() {
			// showdialog.showDialog(context);
			// score_lv_loading.setVisibility(View.VISIBLE);
			// score_lv_tip.setVisibility(View.GONE);
		}

		protected String doInBackground(String... paramsArr) {
			// 处理后台执行的任务，在后台线程执行
			String strResult = null;
			action = paramsArr[1];
			// 获取请求返回值
			strResult = GetRequestParams.getScoreRequestResult(paramsArr[0], action, context);
			// 获取请求返回值
			return strResult;
		}

		// 4.完成后台任务
		protected void onPostExecute(String result) {
			if (result != null) {
				if (action.equals("mobilpartmatchs")) {
					if (!result.equals("[]")) {// 有最新数据
						// 刷新
						showShouDongRefresh(result);
					}
				}
			} else {
				if (!isFirstShowTip) {
					isFirstShowTip = true;
					Toast.makeText(context, context.getString(R.string.problem_01), Toast.LENGTH_LONG).show();
				}
			}
			// 不管有无数据都关闭对话框
			// showdialog.closeDialog();
			// score_lv_loading.setVisibility(View.GONE);
		}
	}

	ScoreFiltergridviewAdapter adapter;
	// 图片的文字标题
	// private String[] titles = new String[] { "赛事1", "赛事2", "赛事3", "赛事4",
	// "赛事5", "赛事6", "赛事7", "赛事8", "赛事9" };
	// 数量数组
	// private int[] nums = new int[] { 2, 1, 3, 5, 6, 2, 8, 10, 12 };
	/** 选中的赛事简称 */
	private List<String> seltitleslist;
	/** 全部赛事简称列表 */
	private List<String> titleslist;
	/** 赛事简称 */
	private String[] titles;
	/** 每项赛事的个数 */
	private int[] nums;
	/** 存放按钮选中状态 */
	List<Map<String, Object>> dilog_btn_select_status = new ArrayList<Map<String, Object>>();

	class CustomfilterDialog extends Dialog {
		private GridView gv;
		List<Map<String, Object>> btn_filter_mData = new ArrayList<Map<String, Object>>();

		public CustomfilterDialog(Context context) {
			super(context);
			// TODO Auto-generated constructor stub
		}

		public CustomfilterDialog(Context context, int theme, List<Map<String, Object>> data) {
			super(context, theme);
			// TODO Auto-generated constructor stub
			btn_filter_mData.clear();
			btn_filter_mData.addAll(ScoreFiltergridviewAdapter.deepCopy(data));
		}

		protected void onCreate(Bundle savedInstanceState) {
			super.onCreate(savedInstanceState);
			// 去掉标题
			try {
				requestWindowFeature(Window.FEATURE_NO_TITLE);
				setContentView(R.layout.score_filter_dialog);
				// 获得GridView实例
				gv = (GridView) findViewById(R.id.mygridview);
				// 处理赛事简称：获取赛事名称数组titles和赛事对应数量nums
				dFilterNameAndNumber();
				// 初始化数据,初始默认赛事全部选中
				if (btn_filter_mData.size() == 0 && titles != null) {
					for (int i = 0; i < titles.length; i++) {
						Map<String, Object> map = new HashMap<String, Object>();
						map.put("isCheck", 1);
						btn_filter_mData.add(map);
					}
				}
				// 开始展现
				adapter = new ScoreFiltergridviewAdapter(titles, nums, context, btn_filter_mData);
				gv.setAdapter(adapter);
				// 头部按钮
				Button top_title_back = (Button) findViewById(R.id.top_title_back);
				top_title_back.setSingleLine(true);
				top_title_back.setOnClickListener(new Button.OnClickListener() {
					public void onClick(View v) {
						dismiss();
					}
				});
				// 多少场赛事可筛选
				TextView tv_dia_sainum = (TextView) findViewById(R.id.tv_dia_sainum);
				int sum = 0;
				if (nums != null) {
					for (int i = 0; i < nums.length; i++) {
						sum += nums[i];
					}
				}
				tv_dia_sainum.setText(sum + "");
				// 底部三个按钮
				// 全选
				Button buttonYes = (Button) findViewById(R.id.button_quanx);
				buttonYes.setSingleLine(true);
				buttonYes.setOnClickListener(new Button.OnClickListener() {
					public void onClick(View v) {
						// 全选状态 修改视图
						adapter.setSelectAllData(/* btn_filter_mData */);
						adapter.notifyDataSetChanged();
					}
				});
				// 全不选
				Button buttonNo = (Button) findViewById(R.id.button_quanbx);
				buttonNo.setSingleLine(true);
				buttonNo.setOnClickListener(new Button.OnClickListener() {
					public void onClick(View v) {
						// //全不选状态 修改视图
						// adapter.setSelectNoData(/*btn_filter_mData*/);
						// adapter.setSelectNoData(btn_filter_mData);
						adapter.setSelectOtherData(/* btn_filter_mData */);
						adapter.notifyDataSetChanged();
					}
				});
				Button buttonCanel = (Button) findViewById(R.id.button_canel);
				buttonCanel.setSingleLine(true);
				buttonCanel.setOnClickListener(new Button.OnClickListener() {
					public void onClick(View v) {
						dismiss();
					}
				});

				// 确定，开始筛选
				Button buttonQued = (Button) findViewById(R.id.button_qued);
				buttonQued.setSingleLine(true);
				buttonQued.setOnClickListener(new Button.OnClickListener() {
					public void onClick(View v) {
						// 拿到选中的赛事简称
						List<String> templist = ScoreFiltergridviewAdapter.deepCopy(adapter.getseltitleslist());
						// System.out.println("templist.size()"+templist.size());
						if (templist.size() == 0) {
							Toast.makeText(context, R.string.select_at_least_one_game2, Toast.LENGTH_SHORT).show();
						} else {
							// 开始筛选，至少选中一个
							seltitleslist = ScoreFiltergridviewAdapter.deepCopy(templist);
							if (matchState != 4) {// 我的关注不受筛选所限
								handleDataByShort(matchState, seltitleslist);
							}
							dilog_btn_select_status.clear();
							dilog_btn_select_status.addAll(ScoreFiltergridviewAdapter.deepCopy(adapter.getSelectData()));
							dismiss();
						}
					}
				});
			} catch (Exception e) {
				// TODO Auto-generated catch block
				// e.printStackTrace();
			}
		}

		// called when this dialog is dismissed
		protected void onStop() {
			// Log.d("TAG", "+++++++++++++++++++++++++++");
		}
	}

	public void setPause(boolean isPause) {
		this.isPause = isPause;
	}

}
